﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AsycServer
{
    /// <summary>
    /// 调试工具
    /// </summary>
    public partial class AsyUdpServer
    {
        void SendThread()
        {
            while (Active)
            {
                while (outMessages.Count > 0)
                {
                    for (int i = 0; i < outMessages.Count; i++)
                    {
                        while (outMessages[i] == null) ;

                        if (DebugInfo.downData && outMessages[0].Message.Size > 1)
                        {
                            string dataString = "";
                            foreach (byte b in outMessages[0].Message.Array) dataString += b + " ";
                            Debug("Sending " + outMessages[0].Message.Size + "[" + dataString + "]");
                        }

                        outMessages[i].Send();
                        upByteBuffer += outMessages[i].Message.Size;
                        upByteTotal += outMessages[i].Message.Size;
                    }

                    outMessages.Clear();
                }

                Thread.Sleep(5);
            }
        }
    }
}